﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class dayRead : Basic
{
    public string strC = "";
    public string strPJBD = "";  //盘前必读
    public string strPZZB = "";  //盘中直播
    public string strPHZN = "";  //盘后指南
    public string strJGSP = "";  //机构收评
    public int ti = 1;  //判断当前直播状态
    public string strTZBW = "";  //投资备忘
    public string strBWRL = "";  //投资备忘日历
    protected void Page_Load(object sender, EventArgs e)
    {
        strPJBD = sb盘前必读(out strPZZB, out strPHZN).ToString();

        strPZZB += sb盘中直播列表(out strJGSP);

        strPHZN += "<div class=\"bidu_content_z\">" + strJGSP + "</div>";

        ti = ptime();

        // OTO.ToDate(Request["date"], DateTime.Now).ToString("yyyy-MM-dd")
        //strTZBW = sb投资备忘("2010-12-28").ToString();
        strTZBW = sb投资备忘(OTO.ToDate(Request["date"], DateTime.Now).ToString("yyyy-MM-dd")).ToString();

        strBWRL = sb投资备忘日历().ToString();

        StringBuilder sb = new StringBuilder();
        switch (ti)
        {
            case 1:
                sb.AppendLine("<!--盘前必读 开始-->");
                sb.AppendLine("<div class=\"bidu_content\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘前必读<a id=\"b1\"></a><div class=\"bidu_bgred\"></div>");
                sb.AppendLine("</div>");
                sb.AppendFormat("<div id=\"ti_1\">{0}</div>",strPJBD);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘前必读 结束-->");

                sb.AppendLine("<!--盘中直播 开始-->");
                sb.AppendLine("<div class=\"bidu_content bidu_magin10\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘中直播<a id=\"b2\"></a><div class=\"bidu_bgred\"></div></div>");
                sb.AppendFormat("<div id=\"ti_2\">{0}</div>",strPZZB);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘中直播 结束-->");

                sb.AppendLine("<!--盘后指南 开始-->");
                sb.AppendLine("<div class=\"bidu_content bidu_magin10\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘后点评<a id=\"b3\"></a><div class=\"bidu_bgred\"></div></div>");
                sb.AppendFormat("<div id=\"ti_3\">{0}</div>",strPHZN);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘后指南 结束-->");
                break;
            case 2:
                sb.AppendLine("<!--盘中直播 开始-->");
                sb.AppendLine("<div class=\"bidu_content\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘中直播<a id=\"b2\"></a><div class=\"bidu_bgred\"></div></div>");
                sb.AppendFormat("<div id=\"ti_2\">{0}</div>",strPZZB);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘中直播 结束-->");

                sb.AppendLine("<!--盘后指南 开始-->");
                sb.AppendLine("<div class=\"bidu_content bidu_magin10\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘后点评<a id=\"b3\"></a><div class=\"bidu_bgred\"></div></div>");
                sb.AppendFormat("<div id=\"ti_3\">{0}</div>",strPHZN);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘后指南 结束-->");

                sb.AppendLine("<!--盘前必读 开始-->");
                sb.AppendLine("<div class=\"bidu_content bidu_magin10\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘前必读<a id=\"b1\"></a><div class=\"bidu_bgred\"></div>");
                sb.AppendLine("</div>");
                sb.AppendFormat("<div id=\"ti_1\">{0}</div>",strPJBD);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘前必读 结束-->");
                break;
            default:
                sb.AppendLine("<!--盘后指南 开始-->");
                sb.AppendLine("<div class=\"bidu_content\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘后点评<a id=\"b3\"></a><div class=\"bidu_bgred\"></div></div>");
                sb.AppendFormat("<div id=\"ti_3\">{0}</div>",strPHZN);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘后指南 结束-->");

                sb.AppendLine("<!--盘前必读 开始-->");
                sb.AppendLine("<div class=\"bidu_content bidu_magin10\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘前必读<a id=\"b1\"></a><div class=\"bidu_bgred\"></div>");
                sb.AppendLine("</div>");
                sb.AppendFormat("<div id=\"ti_1\">{0}</div>",strPJBD);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘前必读 结束-->");

                sb.AppendLine("<!--盘中直播 开始-->");
                sb.AppendLine("<div class=\"bidu_content bidu_magin10\">");
                sb.AppendLine("<div class=\"bidu_content_h h3 blue\"><img src=\"http://down3.emstock.com.cn/www/images/index_ico2.gif\" class=\"img\" />盘中直播<a id=\"b2\"></a><div class=\"bidu_bgred\"></div></div>");
                sb.AppendFormat("<div id=\"ti_2\">{0}</div>",strPZZB);
                sb.AppendLine("</div>");
                sb.AppendLine("<!--盘中直播 结束-->");
                break;
        }

        strC = sb.ToString();

    }

    protected int ptime()
    {
        int rel = 3;
        if (DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 8:00:00") && DateTime.Now <= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:00:00"))
            rel = 1;
        else if (DateTime.Now > Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 10:00:00") && DateTime.Now <= Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 15:30:00"))
            rel = 2;
        else
            rel = 3;
        return rel;
    }

    protected StringBuilder sb盘前必读(out string pzzb, out string phzn)
    {
        StringBuilder sb = new StringBuilder();
        StringBuilder sb5 = new StringBuilder();  //盘中直播
        StringBuilder sb6 = new StringBuilder();  //盘后指南
        try
        {
            PubNews pubNews = new PubNews();
            string url = jsonUrl + "news/NewsListMany.ashx?typeid=0501,0502,0503,0603,0703&top=7";
            string str = Pub.LoadData(url);
            List<NewsList> obj = JsonConvert.DeserializeObject<List<NewsList>>(str);

            StringBuilder sb2 = new StringBuilder();  //盘前必读
            StringBuilder sb3 = new StringBuilder();  //晨迅精华
            StringBuilder sb4 = new StringBuilder();  //媒体精华

            if (obj != null)
            {
                foreach (var m in obj)
                {
                    #region
                    switch (m.typeid)
                    {
                        case "0501":
                            {
                                #region
                                if (m.list.Length > 0)
                                {
                                    sb4.AppendLine("<div class=\"bidu_content_z_r\">");
                                    sb4.AppendLine("<div class=\"bidu_content_b_t bidu_bg\">媒体精华</div>");
                                    sb4.AppendLine("<div class=\"bidu_content_x_x\">");
                                    sb4.AppendLine("<div class=\"h2 center blue\">四大证劵报要闻精华摘要</div>");
                                    sb4.AppendLine("<div class=\"bidu_content_x_x_text\">");
                                    int i = 0;
                                    foreach (var c in m.list)
                                    {
                                        i++;
                                        string source = c.Source;
                                        if (!string.IsNullOrEmpty(source))
                                        {
                                            source = "[" + source + "]";
                                        }
                                        string ss = source + c.Title;
                                        if (!string.IsNullOrEmpty(ss))
                                        {
                                            if (ss.Length > 24)
                                            {
                                                ss = ss.Substring(0, 24);
                                            }
                                        }
                                        sb4.AppendLine("<li><a href=\"" + GetNewsUrl("01", "0501", c.Id) + "\" class=\"g\">" + ss + "</a></li>");
                                        if (i == 7)
                                        {
                                            break;
                                        }
                                    }
                                    sb4.AppendLine("</div>");
                                    sb4.AppendLine("</div>");
                                    sb4.AppendLine("</div>");
                                }
                                #endregion
                                continue;
                            }
                        case "0502":
                            {
                                #region
                                if (m.list.Length > 0)
                                {
                                    sb2.AppendLine("<div class=\"bidu_content_m_2_c\">");
                                    sb2.AppendLine("<ul>");
                                    sb2.AppendLine("<li class=\"h2 center blue\"><a href=\"" + GetNewsUrl("01", "0502", m.list[0].Id) + "\"  class=\"b\">" + m.list[0].Title + "</a></li>");
                                    sb2.AppendLine("<li class=\"font12 text-indent\">" + pubNews.GetBriefByID((long)m.list[0].Id) + "<a href=\"" + GetNewsUrl("01", "0703", m.list[0].Id) + "\" class=\"r\">[详细]</a></li>");
                                    sb2.AppendLine("</ul>");
                                    sb2.Append("<div style=\"text-align:center;color:gray;\">(此信息来源于益盟高端信息资讯软件-<a href=\"http://chat10.live800.com/live800/chatClient/chatbox.jsp?jid=3968645766&companyID=87735&configID=163194&skillId=8757&enterurl=http%3A%2F%2Fchat10%2Elive800%2Ecom%3A8080%2Flive800%2Fpreview%2Ejsp&tm=1299136645122\" class=\"b\">睿讯通</a>，睿讯通体验申请热线400-670-7799)</div>");
                                    sb2.AppendLine("</div>");
                                }
                                #endregion
                                continue;
                            }
                        case "0503":
                            {
                                #region
                                if (m.list.Length > 0)
                                {
                                    sb3.AppendLine("<div class=\"bidu_content_z_l\">");
                                    sb3.AppendLine("<div class=\"bidu_content_b_t bidu_bg\">晨迅精华</div>");
                                    sb3.AppendLine("<div class=\"bidu_content_x_x\">");
                                    sb3.AppendLine("<div class=\"h2 center blue\"><a href=\"" + GetNewsUrl("01", "0503", m.list[0].Id) + "\"  class=\"b\">" + m.list[0].Title + "</a></div>");
                                    sb3.AppendLine("<div class=\"bidu_content_x_x_text\">" + pubNews.GetBriefByID((long)m.list[0].Id) + "");
                                    sb3.AppendLine("<span class=\"bidu_content_m_r\"><a href=\"" + GetNewsUrl("01", "0503", m.list[0].Id) + "\" class=\"r\">[详细]</a></span></div>");
                                    sb3.AppendLine("</div>");
                                    sb3.AppendLine("</div>");
                                }
                                #endregion
                                continue;
                            }
                        case "0603":
                            {
                                #region
                                if (m.list.Length > 0)
                                {
                                    sb5.AppendLine("<div class=\"bidu_content_m_2_c\">");
                                    sb5.AppendLine("<ul>");
                                    sb5.AppendLine("<li class=\"h2 center blue\"><a href=\"" + GetNewsUrl("01", "0603", m.list[0].Id) + "\"  class=\"b\">" + m.list[0].Title + "</a></li>");
                                    sb5.AppendLine("<li class=\"font12 text-indent\">" + pubNews.GetBriefByID((long)m.list[0].Id) + "<a href=\"" + GetNewsUrl("01", "0603", m.list[0].Id) + "\" class=\"r\">[详细]</a></li>");
                                    sb5.AppendLine("</ul>");
                                    sb5.AppendLine("</div>");
                                }
                                #endregion
                                continue;
                            }
                        case "0703":
                            {
                                #region
                                if (m.list.Length > 0)
                                {
                                    sb6.AppendLine("<div class=\"bidu_content_m_2_c\">");
                                    sb6.AppendLine("<ul>");
                                    sb6.AppendLine("<li class=\"h2 center blue\"><a href=\"" + GetNewsUrl("01", "0703", m.list[0].Id) + "\"  class=\"b\">" + m.list[0].Title + "</a></li>");
                                    sb6.AppendLine("<li class=\"font12 text-indent\">" + pubNews.GetBriefByID((long)m.list[0].Id) + "<a href=\"" + GetNewsUrl("01", "0703", m.list[0].Id) + "\" class=\"r\">[详细]</a></li>");
                                    sb6.AppendLine("</ul>");
                                    sb6.AppendLine("</div>");
                                }
                                #endregion
                                continue;
                            }
                    }
                    #endregion
                }
            }
            sb.Append(sb2.ToString());
            sb.AppendLine("<div class=\"bidu_content_z\">");
            sb.Append(sb3.ToString());
            sb.Append(sb4.ToString());
            sb.AppendLine("</div>");
        }
        catch { }

        pzzb = sb5.ToString();
        phzn = sb6.ToString();
        return sb;
    }

    protected StringBuilder sb盘中直播列表(out string 机构收评)
    {
        StringBuilder sb = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();  //实时解盘0601
        StringBuilder sb3 = new StringBuilder();  //个股点评0602
        StringBuilder sb4 = new StringBuilder();  //机构收评0701
        try
        {
            PubNews pubNews = new PubNews();
            string url = jsonUrl + "news/NewsListMany.ashx?typeid=0601,0602,0701&top=8";
            string str = Pub.LoadData(url);
            List<NewsList> obj = JsonConvert.DeserializeObject<List<NewsList>>(str);

            foreach (var m in obj)
            {
                #region
                switch (m.typeid)
                {
                    case "0601":
                        {
                            #region
                            if (m.list.Length > 0)
                            {
                                sb2.AppendLine("<div class=\"bidu_content_z_l\">");
                                sb2.AppendLine("<div class=\"bidu_content_b_t bidu_bg\">实时解盘</div>");
                                sb2.AppendLine("<div class=\"bidu_content_x_x\">");
                                sb2.AppendLine("<ul class=\"bidu_14ul\">");
                                foreach (var n in m.list)
                                {
                                    sb2.AppendLine("<li><a href=\"" + GetNewsUrl("01", m.typeid, n.Id) + "\"  class=\"b\">" + n.Title + "</a></li>");
                                }
                                sb2.AppendLine("</ul>");
                                sb2.AppendLine("</div>");
                                sb2.AppendLine("</div>");
                            }
                            #endregion
                            continue;
                        }
                    case "0602":
                        {
                            #region
                            if (m.list.Length > 0)
                            {
                                sb3.AppendLine("<div class=\"bidu_content_z_r\">");
                                sb3.AppendLine("<div class=\"bidu_content_b_t bidu_bg\">个股点评</div>");
                                sb3.AppendLine("<div class=\"bidu_content_x_x\">");
                                sb3.AppendLine("<ul class=\"bidu_14ul\">");
                                foreach (var n in m.list)
                                {
                                    sb3.AppendLine("<li><a href=\"" + GetNewsUrl("01", m.typeid, n.Id) + "\"  class=\"b\">" + n.Title + "</a></li>");
                                }
                                sb3.AppendLine("</ul>");
                                sb3.AppendLine("</div>");
                                sb3.AppendLine("</div>");
                            }
                            #endregion
                            continue;
                        }
                    case "0701":
                        {
                            #region
                            if (m.list.Length > 0)
                            {
                                sb4.AppendLine("<div class=\"bidu_content_z_l\">");
                                sb4.AppendLine("<div class=\"bidu_content_b_t bidu_bg\">机构收评</div>");
                                sb4.AppendLine("<div class=\"bidu_content_x_x\">");
                                sb4.AppendLine("<ul class=\"bidu_14ul\">");
                                foreach (var n in m.list)
                                {
                                    sb4.AppendLine("<li><a href=\"" + GetNewsUrl("01", m.typeid, n.Id) + "\"  class=\"b\">" + n.Title + "</a></li>");
                                }
                                sb4.AppendLine("</ul>");
                                sb4.AppendLine("</div>");
                                sb4.AppendLine("</div>");
                            }
                            #endregion
                            continue;
                        }
                }
                #endregion
            }

        }
        catch { }

        //拼接益盟名师解盘

        try
        {
            string str = Pub.LoadData(jsonUrl + "news/msjp.ashx");
            List<MSJPEnty> list = JsonConvert.DeserializeObject<List<MSJPEnty>>(str);
            sb4.AppendLine("<div class=\"bidu_content_z_r\">");
            sb4.AppendLine("<div class=\"bidu_content_b_t bidu_bg\">益盟名师解盘<span class=\"bidu_more2\"></span></div>");
            sb4.AppendLine("<div class=\"bidu_content_x_x\">");
            sb4.AppendLine("<ul>");
            int i = 0;
            foreach (var m in list)
            {
                i++;
                sb4.AppendFormat("<li><a href=\"{1}\"><img src=\"http://down3.emstock.com.cn/www/images/ms/{2}.jpg\" alt=\"上海著名证券分析师\" vspace=\"3\" align=\"left\" border=\"0\" class=\"img\" /></a><span class=\"font14 blue\">{0}：</span>", m.name, m.lst[0].Url, i);
                if (m.lst.Count > 0)
                {
                    sb4.AppendFormat("<a href=\"{0}\" target=\"_blank\">{1} ({2})</a>", m.lst[0].Url, m.lst[0].Title, OTO.ToDate(m.lst[0].PTime, DateTime.Now).ToString("yyyy-MM-dd"));
                }
                sb4.AppendFormat("</li>");
                sb4.AppendFormat("<div class=\"clearok\"></div>");
            }
            sb4.AppendLine("</ul>");
            sb4.AppendLine("</div>");
            sb4.AppendLine("</div>");
        }
        catch { }

        机构收评 = sb4.ToString();
        sb.Append("<div class=\"bidu_content_z\">" + sb2.ToString() + sb3.ToString() + "</div>");
        return sb;
    }

    protected StringBuilder sb投资备忘(string date)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "comm/InvestmentMemo.ashx?date=" + date;
            string str = Pub.LoadData(url);
            List<InvestmentMemoEnty> list = JsonConvert.DeserializeObject<List<InvestmentMemoEnty>>(str);

            var list2 = list.Select(o => o.Type).Distinct().ToList();

            foreach (var m in list2)
            {
                int p = 0;
                switch (m)
                {
                    case "股东大会召开日":
                    case "股东资格登记日":
                    case "实行特别处理日":
                    case "网络投票开始日":
                    case "撤销特别处理日":
                    case "网络投票结束日":
                        p = 1;
                        break;
                    case "分红转增股权登记日":
                    case "分红转增除权除息日":
                    case "分红转增股份上市日":
                    case "分红转增红利发放日":
                        p = 2;
                        break;
                    case "新股申购":
                    case "新股上市":
                    case "增发新股招股书刊登日":
                        p = 3;
                        break;
                    default:
                        p = 0;
                        break;
                }

                sb.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#d1d3d2\"  width=\"100%\" class=\"aa\" btab=\"true\" btabv=\"" + p + "\">");
                sb.AppendLine("  <tr>");
                sb.AppendLine("    <td colspan=\"2\" bgcolor=\"#f1f1f3\" class=\"bidu_padding12\">" + m + "</td>");
                sb.AppendLine("  </tr>");
                List<InvestmentMemoEnty> list3 = new List<InvestmentMemoEnty>();
                list3 = list.Where(o => o.Type.Equals(m)).ToList();
                foreach (var n in list3)
                {
                    sb.AppendLine("  <tr>");
                    sb.AppendFormat("    <td width=\"60\" bgcolor=\"#FFFFFF\" class=\"bidu_padding10\"><a href=\"{2}gg{1}.shtml\">{0}</a></td>", n.StockName, n.Stock, quoteUrl);
                    sb.AppendLine("    <td bgcolor=\"#FFFFFF\" class=\"bidu_padding11\">" + n.Content + "</td>");
                    sb.AppendLine("  </tr>");
                }
                sb.AppendLine("</table>   ");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb投资备忘日历()
    {
        StringBuilder sb = new StringBuilder();
        DateTime dt = DateTime.Now;
        if (Request["date"] != null)
            dt = OTO.ToDate(Request["date"], dt);
        sb.Append(sb日历(dt.AddDays(-2), 0));
        sb.Append(sb日历(dt.AddDays(-1), 0));
        sb.Append(sb日历(dt, 1));
        sb.Append(sb日历(dt.AddDays(1), 0));
        sb.Append(sb日历(dt.AddDays(2), 0));
        return sb;
    }

    protected StringBuilder sb日历(DateTime date, int v)
    {
        StringBuilder sb = new StringBuilder();
        if (v == 1)
        {
            sb.AppendFormat("<div class=\"bidu_beiwang_ri_on bidu_bg\" onclick=\"return SelDate('{0}')\">", date.ToString("yyyy-MM-dd"));
            sb.AppendLine(" <ul>");
            sb.AppendLine("   <li class=\"bidu-w\">" + Pub.DateGetWeek(date) + " </li>");
            sb.AppendLine("   <li class=\"h1 red\">" + date.ToString("dd") + "</li>");
            sb.AppendLine("   <li>" + Pub.DateGetMonth(date) + "</li>");
            sb.AppendLine(" </ul>");
            sb.AppendLine("</div>");
        }
        else
        {
            sb.AppendFormat("<div class=\"bidu_beiwang_ri_off bidu_bg\" onclick=\"return SelDate('{0}')\">", date.ToString("yyyy-MM-dd"));
            sb.AppendLine(" <ul>");
            sb.AppendLine("   <li class=\"bidu-w\">" + Pub.DateGetWeek(date) + " </li>");
            sb.AppendLine("   <li class=\"h1 gray\">" + date.ToString("dd") + "</li>");
            sb.AppendLine("   <li>" + Pub.DateGetMonth(date) + "</li>");
            sb.AppendLine(" </ul>");
            sb.AppendLine("</div>");
        }
        return sb;
    }




}